package com.x86.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.x86.util.JwtUtil;
import com.x86.util.ResponseResult;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.x86.domain.Admin;
import com.x86.mapper.AdminMapper;
import com.x86.service.AdminService;

/**
 * @author 风亦未止
 * @date 2022/3/24 18:48
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {


    @Override
    public ResponseResult login(String username, String password) {
        Admin one = lambdaQuery().eq(Admin::getUsername, username).one();
        if (ObjectUtil.isNull(one)) return ResponseResult.failure("用户不存在");
        if (password.equals(one.getPassword())) {
            String tokenByAdmin = JwtUtil.getTokenByAdmin(one);
            return ResponseResult.success("登录成功！",tokenByAdmin);
        }
        return ResponseResult.failure("密码错误！");
    }
}


